﻿using System.Reflection;
using Abp.Modules;
using Abp.AutoMapper;
using AVIS.OutBound.CarGroups.Dto;
using AVIS.OutBound.CarGroups;
using AVIS.OutBound.Orders.Dto;
using AVIS.OutBound.Orders;
using System.Collections.Generic;
using AVIS.OutBound.BookOrders;
using AVIS.OutBound.BookOrders.Dto;

namespace AVIS.OutBound
{
    [DependsOn(
        typeof(AbpAutoMapperModule),
        typeof(OutBoundCoreModule))]
    public class OutBoundApplicationModule : AbpModule
    {
        public override void PreInitialize()
        {
            // 配置对象映射的关系
            Configuration.Modules.AbpAutoMapper().Configurators.Add(config =>
            {
                // 车组（CarGroup -> CarGroupDto）
                config.CreateMap<CarGroup, CarGroupDto>()
                    .ForMember(u => u.PriceIncludeContents, options => options.MapFrom(input => input.PriceInclue.Contents)) // 车组套餐价格包含
                    .ForMember(u => u.IsAutomatic, options => options.MapFrom(input => input.Feature.IsAutomatic)) // 是否为自动挡
                    .ForMember(u => u.Suitcases, options => options.MapFrom(input => input.Feature.GetCNSuitcases())) // 行李箱
                    .ForMember(u => u.Seats, options => options.MapFrom(input => string.IsNullOrWhiteSpace(input.Feature.Seats) ? "0" : input.Feature.Seats)); // 车辆有几座（如：2座、4座等）

                // 订单（Order -> OrderOutput）
                config.CreateMap<Order, OrderOutput>()
                    .ForMember(u => u.RateName, options => options.MapFrom(input => input.RatePackage != null ? input.RatePackage.Name : "")) // 套餐名称
                    .ForMember(u => u.RateContents, options => options.MapFrom(input => input.RatePackage != null ? input.RatePackage.GetContent() : new List<string>())); // 套餐内容

                // 预定单（BookOrder -> BookOrderOutput）
                config.CreateMap<BookOrder, BookOrderOutput>()
                    .ForMember(u => u.RateName, options => options.MapFrom(input => input.RatePackage != null ? input.RatePackage.Name : "")) // 套餐名称
                    .ForMember(u => u.RateContents, options => options.MapFrom(input => input.RatePackage != null ? input.RatePackage.GetContent() : new List<string>())); // 套餐内容


            });
        }

        public override void Initialize()
        {
            IocManager.RegisterAssemblyByConvention(Assembly.GetExecutingAssembly());
        }
    }
}
